from ipywidgets import StaticInteract, RangeWidget, RadioWidget
from astropy import coordinates
from astropy import units as u
from astropy.io import fits
import aplpy
import pylab
dpath = '/Volumes/128gbdisk/w51/'
/Users/adam/virtual-python/lib/python2.7/site-packages/matplotlib-1.4.x-py2.7-macosx-10.6-intel.egg/mpl_toolkits/__init__.py:2: UserWarning: Module argparse was already imported from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc, but /Users/adam/virtual-python/lib/python2.7/site-packages is being added to sys.path
__import__('pkg_resources').declare_namespace(__name__)
hdu = fits.open(dpath+'W51Ku_BDarray_continuum_2048_both_uniform.hires.clean.image.fits')
for ii in [3,4]:
for kk in ['CRVAL','CTYPE','CDELT','CRPIX','CUNIT','NAXIS']:
k = kk+str(ii)
if k in hdu[0].header:
del hdu[0].header[k]
hdu[0].header['NAXIS'] = 2
hdu[0].data = hdu[0].data.squeeze()
hdu2 = fits.open(dpath+'H2CO_22_Ku_D_taucube_rebin.fits')
yy,xx = np.indices(hdu2[0].data.shape[1:])
rr = ((xx-hdu2[0].data.shape[2]/2-1)**2+(yy-hdu2[0].data.shape[1]/2-1)**2)**0.5
mask = rr < 200
nanmask = np.zeros_like(mask,dtype='float')
nanmask[True-mask] = np.nan
hdu2[0].data += nanmask
h=hdu2[0].header
velocities = 1e-3 * ((np.arange(h['NAXIS3'])+1-h['CRPIX3'])*h['CDELT3']+h['CRVAL3'])
def make_plot(overlay_layer=0):
fig=figure(figsize=(10,10))
F = aplpy.FITSFigure(hdu,convention='calabretta',figure=fig)
F.tick_labels.set_xformat('dd.dd')
F.tick_labels.set_yformat('dd.dd')
F.tick_labels.set_font(size=20)
F.axis_labels.set_font(size=20)
F.show_grayscale(stretch='arcsinh',vmin=-5e-4,vmax=0.011)
F.recenter(290.92345,14.511772,radius=1.5/60.)
F.show_contour(hdu2,levels=[0.03,0.08,0.12,15.0],colors=[(0.8,0.2,0.0,0.2),(0.8,0.2,0.0,0.4),(0.8,0.2,0.0,0.6)],
filled=True,
slices=[overlay_layer])
kms = velocities[overlay_layer]
F.add_label(0.9,0.9,"v=%0.1f km/s" % kms,relative=True, color='r', size=20)
return fig
StaticInteract(make_plot,
overlay_layer=RangeWidget(0,20,1))
!ipython nbconvert InteractiveFigure.ipynb --to html
!ipython nbconvert InteractiveFigure.ipynb --to slides --template output_toggle --reveal-prefix="//cdn.jsdelivr.net/reveal.js/2.4.0/"
/Users/adam/virtual-python/lib/python2.7/site-packages/Pygments-1.6-py2.7.egg/pygments/plugin.py:39: UserWarning: Module argparse was already imported from /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/argparse.pyc, but /Users/adam/virtual-python/lib/python2.7/site-packages is being added to sys.path import pkg_resources [NbConvertApp] Using existing profile dir: u'/Users/adam/.ipython/profile_default' Logging to /Users/adam/work/w51/ipython_log_2013-12-06.py [NbConvertApp] Converting notebook InteractiveFigure.ipynb to html [NbConvertApp] Support files will be in InteractiveFigure_files/ [NbConvertApp] Loaded template html_full.tpl [NbConvertApp] Writing 10367810 bytes to InteractiveFigure.html